01Objectives & setup
Goal
Learn to use a workstation in a Linux environment.
Software
VirtualBox.
Assessment
A detailed report written with a word processor.
Manipulation
- Import the file
RockyLinux 9.4.ovainto VirtualBox. Download: Google Drive link. - The virtual machine to use is RockyLinux (the replacement for CentOS).
User account
User: toto · Password: toto01
Administrator (root)
User: root · Password: linux2002
02Introduction & directory structure
We use Linux to learn system administration. A key advantage: most configuration files are text files, editable with simple tools such as gedit, nano or emacs. Most Unix-derived systems share a similar directory hierarchy:
| Directory | Sub-directories | Content |
|---|---|---|
/bin | /usr/bin /usr/local/bin | Basic commands; additional commands added by the admin. |
/sbin | /usr/sbin | System administration commands. |
/boot | Linux kernel files. | |
/dev | Special device files (peripherals). | |
/etc | /etc/rc.d /etc/init.d | System configuration files; service startup scripts. |
/home | Users' personal directories. | |
/lib | /usr/lib | Libraries (shared code) used by programs. |
/mnt | /mnt/cdrom /mnt/usb | Mount points for removable media (CD, USB). |
/root | Home directory of the administrator. | |
/tmp | Temporary files. | |
/usr | /usr/include /usr/share/man | Main system directory: header files, Linux manuals. |
/var | /var/log /var/spool | Variable data: system logs, mailboxes. |
03Part 1 — Generalities and organisation
Explore the Linux file tree:
- In which directory is your
$HOMEdirectory located (where$HOMEis your login)? - Which files and directories does your
$HOMEcontain? (Don't forget "hidden" files, starting with a.) - Go back to your
$HOME. Using the graphical interface (right-click menu), create then delete a folder and a file in$HOME. - Task: create the following tree, starting from your
$HOME:
04Part 2 — The command interpreter (shell)
Command-line interpreters (shells) such as bash let you work faster than with a graphical interface.
- Launch a shell: open the terminal. A line ending with
$appears: this is the prompt. - Explore these commands:
- Find out what
whoamiandpsdo. Useman [command]to read the documentation (pressqto quit). - Look up
pwd,whoamiandps.
- Find out what
- Aliases (shortcuts):
- What does
lsdo? Check with the file manager. - Try
ls -a,ls -al, thenls -al --color=auto. Compare the results. - Use
man aliasto see how to create one. - Task: create an alias named
llcthat behaves likels -la --color=auto, and check that it works. - Type
exitto close the shell. Open a new one and tryllcagain: it has disappeared (it was temporary). To make it permanent, add it to the.bashrcfile.
- What does
05Part 3 — Moving in a directory tree
Enter a folder
cd [folder_name]
Go up one level
cd ..
- Create a directory
TP2inside theLinuxdirectory. - Open a terminal. Check you are in
$HOMEwithpwd, and check its content withls. - Enter the
Programmationdirectory. Check withpwd. - Leave
Programmation. Check withpwd. - Go to your
TP2directory (Linux→TP2). Check withpwd.
06Part 4 — File creation & manipulation
| Command | Function | Syntax | Example |
|---|---|---|---|
touch | Create an empty file | touch [PATH/]FILE | touch /mmi/test |
nano | Edit a text file | nano [PATH/]FILE | nano /mmi/test |
less | View content | less [PATH/]FILE | less /mmi/test |
rm | Remove a file | rm [PATH/]FILE | rm /mmi/test |
mv | Move or rename | mv SOURCE DEST | mv test test2 |
cp | Copy a file | cp SOURCE DEST | cp test test2 |
- Go to the
TP2sub-directory, then create an empty file namedbonjourwithtouch(check themanpages if needed). - Check that the file is empty with
cat. - Write "Hello World" into
bonjour: typecat > bonjour, then the sentence. Finish with Ctrl + D. - Display the content of
bonjourwithcat. - Add "How do you do?" at the end of
bonjour: typecat >> bonjour, then your text. Finish with Ctrl + D. - Check the result by displaying
bonjouragain. - With
cp, copybonjourinto a new file namedsalut(still inTP2). Check that both files are identical withdiff. - Type
cat > salut, then a new sentence, and finish with Ctrl + D. Displaysalut. What happened? What is the difference between>and>>?
> and >> are called redirection symbols.07Part 5 — Access rights (permissions)
In Linux, every file or folder has rights for three types of users: the owner (user), the group and others. The rights are read (r), write (w) and execute (x).
- Make sure you are in your
TP2directory. - Display the details of the files with
ls -l(or your aliasllc) and look at the first column (e.g.-rw-r--r--). - Make
bonjourconfidential by removing read rights for the group and others:chmod go-r bonjour(ggroup,oothers,-remove,rread). - Check the result with
ls -l. You should see something like-rw-------. - Now let everyone write to the file (dangerous in real life!):
chmod a+w bonjour(afor all). Check again withls -l. - Restore the original rights (read/write for you, read-only for others) with octal notation:
chmod 644 bonjour.
4 = read (r)
6 = 4 + 2 → rw-
2 = write (w)
7 = 4 + 2 + 1 → rwx
1 = execute (x)
644 → rw-r--r--
08Part 6 — Search, wildcards and cleanup
- Create 3 more empty files:
touch note1.txt note2.txt image.jpg - Use the wildcard
*to list all files starting with "note":ls note* - List all files with the ".txt" extension:
ls *.txt - Delete
image.jpg:rm image.jpg. The system may ask for confirmation: type "y". - Delete all files starting with "note" in one command:
rm note* - Go up one level to leave
TP2:cd .. - Try to delete the folder with
rm TP2. What happens? By default,rmdoes not delete directories. - To delete a directory and all its content (
bonjourandsalut), use the recursive option:rm -r TP2 - Check that the folder has gone with
ls.